package com.jsd2412.backend.room.service.impl;

import com.jsd2412.backend.room.mapper.RoomMapper;
import com.jsd2412.backend.room.pojo.dto.RoomQuery;
import com.jsd2412.backend.room.pojo.dto.RoomSaveParam;
import com.jsd2412.backend.room.pojo.entity.Room;
import com.jsd2412.backend.room.pojo.vo.RoomVO;
import com.jsd2412.backend.room.service.RoomService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.Date;
import java.util.List;
@Slf4j
@Service
public class RoomServiceImpl implements RoomService {
    @Autowired
    private RoomMapper roomMapper;
    @Override
    public void save(RoomSaveParam roomSaveParam) {
        log.debug("保存房间业务:{}",roomSaveParam);
        Room room = new Room();
        BeanUtils.copyProperties(roomSaveParam,room);
        if (room.getId()==null){
            room.setCreatedTime(new Date());
            log.debug("新增房间业务:{}",room);
            roomMapper.insert(room);
        }else {
            room.setUpdatedTime(new Date());
            log.debug("修改房间业务:{}",room);
            roomMapper.update(room);
        }
    }

    @Override
    public void delete(Integer id) {
        log.debug("删除房间业务:{}",id);
        roomMapper.delete(id);
    }

    @Override
    public List<RoomVO> select(RoomQuery roomQuery) {
        log.debug("查询房间业务:{}", roomQuery);
        List<RoomVO> list = roomMapper.select(roomQuery);
        return list;
    }
}
